<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form :inline="true" :model="formModel">
        <el-form-item class="no-warn-item" label="用户登录名:" prop="username">
          <el-input v-model="formModel.username" disabled>
            <el-button slot="append" type="primary" icon="el-icon-search" @click="queryUser"></el-button>
          </el-input>
        </el-form-item>
        <el-form-item class="no-warn-item" label="业务类型:" prop="businessType">
          <hey-select v-model="formModel.businessType" clcd="business_type_cd" />
        </el-form-item>
        <el-row class="submit-area">
          <el-col :span="24">
            <el-button type="primary" v-if="hasPermission('business_authority_select')" plain @click="queryList(false)">查询</el-button>
            <el-button type="primary" v-if="hasPermission('business_authority_clear')" plain @click="clearCondition">清除</el-button>
            <el-button type="primary" v-if="hasPermission('business_authority_add')" plain @click="handleAdd">新增权限</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <h3>用户业务权限列表:</h3>
    <hey-table ref="table" :columns="columns" :auto-width="false" @row-click="handleRowClick" :is-radio="true">
      <template slot="tools">
        <el-table-column
          label="操作"
          width="160"
          fixed="right"
          header-align="center"
          align="center"
        >
          <template slot-scope="{row}">
            <span class="hey_tools_btn" v-if="hasPermission('business_authority_edit')" @click="handleEdit(row)">编辑</span>
            <span class="hey_tools_btn" v-if="hasPermission('business_authority_del')" @click="handleDelete(row)">删除</span>
          </template>
        </el-table-column>
      </template>
    </hey-table>
    <h3>详细信息列表:</h3>
    <hey-table ref="table1" :table-data="tableData1" :columns="columns1" :auto-width="false"/>
    <el-dialog
      v-dialogDrag
      v-if="dialogVisible"
      :close-on-click-modal="false"
      title="用户业务权限配置"
      :visible.sync="dialogVisible"
      width="80%"
    >
      <business-authority-mnt :page-type="operType" :edit-data="editData" @mntSuc="queryList" />
    </el-dialog>
    <el-dialog
      v-dialogDrag
      v-if="showUser"
      :close-on-click-modal="false"
      title="用户信息"
      :visible.sync="showUser"
      width="90%"
      append-to-body
    >
      <user-dialog @queryUserSuc="queryUserSuc"/>
    </el-dialog>

  </div>
</template>

<script>
  export default {
    name: 'BusinessAuthorityList',
    components: {
      BusinessAuthorityMnt: () => import('./business-authority-mnt'),
      UserDialog: () => import('@/views/dialog/user-dialog')
    },
    props: {},
    data() {
      return {
        dialogVisible: false,
        showUser: false,
        operType: '',
        editData: {},
        tableData1:[],
        formModel: {
          userid: '',
          username: '',
          isDelete: '0',
          businessType: '',
        },
        columns: [
          { title: '用户登录名', key: 'username'},
          { title: '业务类型', key: 'businessType',clcd:'business_type_cd'},
          { title: '创建时间', key: 'createTime' },
          { title: '创建人', key: 'createUsername' },
          { title: '最后修改时间', key: 'lastUpdateTime'},
          { title: '最后修改人', key: 'lastUpdateUsername' },
        ],
        columns1: [
          { title: '权限代码', key: 'authorityCd' },
          { title: '权限描述', key: 'authorityDesc' },
          { title: '创建时间', key: 'createTime' },
          { title: '创建人', key: 'createUsername' },
          { title: '最后修改时间', key: 'lastUpdateTime'},
          { title: '最后修改人', key: 'lastUpdateUsername' },
        ],
      }
    },
    computed: {

    },
    mounted() {

    },
    methods: {
      clearCondition(){
        this.resetObj(this.formModel)
        this.formModel.isDelete = '0'
      },
      queryUser(){
        this.showUser = true
      },
      queryUserSuc(data){
        this.formModel.username = data.username
        this.formModel.userid = data.userid
      },
      handleRowClick(row) {
        if (row) {
          const param = {}
          param.isDelete = '0'
          param.userid = row.userid
          param.businessType = row.businessType
          this.$refs.table1.query('/user/queryUserBusinessAuthorityDetailInfo', param, '', false)
        } else {
          //清空子表数据
          this.tableData1 = []
        }
      },
      queryList() {
        this.tableData1 = []
        this.$refs.table.query('/user/queryUserBusinessAuthority', this.formModel, '', false)
      },
      handleAdd() {
        this.operType = 'add'
        this.dialogVisible = true
      },
      handleEdit(row) {
        const param = {pageNum:1,pageSize:9999}
        param.userid = row.userid
        param.businessType = row.businessType
        param.isDelete = '0'
        this.get('/user/queryUserBusinessAuthorityDetailInfo', param).then(res => {
          if(res.list){
            const arr = res.list
            row.authorityList = []
            for(let i=0;i<arr.length;i++){
              row.authorityList.push(arr[i].authorityId)
            }
            this.operType = 'edit'
            this.editData = row || {}
            this.dialogVisible = true
          }
        })
      },
      handleDelete(row) {
        this.$sure('确认删除？', _ => {
          this.post('/user/maintainUserBusinessAuthority', { userid: row.userid,businessType:row.businessType,operateType:'03'}).then(_ => {
            this.$info('删除成功', this.queryList)
          })
        })
      },
    }
  }
</script>

<style lang="scss" scoped>

</style>
